home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 October
/
CHIP Turkiye Ekim 2000.iso
/
prog
/
naps
/
04
/
setup.exe
/
Gnucleus
/
PrefSearch.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2000-06-24
|
10KB
|
430 lines
/********************************************************************************
Gnucleus - A node application for the Gnutella network
Copyright (C) 2000 John Marshall
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For support, questions, comments, etc...
E-Mail:
swabby@c0re.net
Address:
21 Cadogan Way
Nashua, NH, USA 03062
********************************************************************************/
// PrefSearch.cpp : implementation file
//
#include "stdafx.h"
#include "Gnucleus.h"
#include "GnucleusDoc.h"
#include "PrefSearch.h"
#include "IPFilter.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPrefSearch property page
IMPLEMENT_DYNCREATE(CPrefSearch, CPropertyPage)
CPrefSearch::CPrefSearch() : CPropertyPage(CPrefSearch::IDD)
{
Doc = NULL;
//{{AFX_DATA_INIT(CPrefSearch)
//}}AFX_DATA_INIT
}
CPrefSearch::~CPrefSearch()
{
}
void CPrefSearch::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPrefSearch)
DDX_Control(pDX, IDC_EDIT_SEARCH, m_ebSearch);
DDX_Control(pDX, IDC_EDIT_NODE, m_ebNode);
DDX_Control(pDX, IDC_EDIT_REPLY, m_ebReply);
DDX_Control(pDX, IDC_CHECK_REPLY, m_chkReply);
DDX_Control(pDX, IDC_COMBO_SEARCH, m_cmbSearch);
DDX_Control(pDX, IDC_COMBO_NODE, m_cmbNode);
DDX_Control(pDX, IDC_LIST_SEARCH, m_lstSearch);
DDX_Control(pDX, IDC_LIST_NODE, m_lstNode);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPrefSearch, CPropertyPage)
//{{AFX_MSG_MAP(CPrefSearch)
ON_BN_CLICKED(IDC_CHECK_REPLY, OnCheckReply)
ON_EN_CHANGE(IDC_EDIT_REPLY, OnChangeEditReply)
ON_EN_CHANGE(IDC_EDIT_SEARCH, OnChangeEditSearch)
ON_CBN_EDITCHANGE(IDC_COMBO_SEARCH, OnEditchangeComboSearch)
ON_BN_CLICKED(IDC_BUTTON_SEARCH_REMOVE, OnButtonSearchRemove)
ON_BN_CLICKED(IDC_BUTTON_SEARCH_ADD, OnButtonSearchAdd)
ON_EN_CHANGE(IDC_EDIT_NODE, OnChangeEditNode)
ON_CBN_EDITCHANGE(IDC_COMBO_NODE, OnEditchangeComboNode)
ON_BN_CLICKED(IDC_BUTTON_NODE_REMOVE, OnButtonNodeRemove)
ON_BN_CLICKED(IDC_BUTTON_NODE_ADD, OnButtonNodeAdd)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPrefSearch message handlers
BOOL CPrefSearch::OnInitDialog()
{
CPropertyPage::OnInitDialog();
Doc = (CGnucleusDoc *) ((CGnucleusApp *) AfxGetApp())->MasterDoc;
CRect rect;
// Setup search list
int offSet;
if(m_lstSearch.GetScrollLimit(SB_VERT))
offSet = ::GetSystemMetrics(SM_CXVSCROLL) + 3;
else
offSet = 4;
m_lstSearch.GetWindowRect(&rect);
m_lstSearch.InsertColumn(0, "File Type", LVCFMT_LEFT,
(rect.Width() - offSet) * 2/3, 0);
m_lstSearch.InsertColumn(1, "Rule", LVCFMT_LEFT,
(rect.Width() - offSet) * 1/3, 1);
m_lstSearch.SetExtendedStyle(LVS_EX_FULLROWSELECT);
// Setup node list
if(m_lstNode.GetScrollLimit(SB_VERT))
offSet = ::GetSystemMetrics(SM_CXVSCROLL) + 3;
else
offSet = 4;
m_lstNode.GetWindowRect(&rect);
m_lstNode.InsertColumn(0, "IP", LVCFMT_LEFT,
(rect.Width() - offSet) * 2/3, 0);
m_lstNode.InsertColumn(1, "Rule", LVCFMT_LEFT,
(rect.Width() - offSet) * 1/3, 1);
m_lstNode.SetExtendedStyle(LVS_EX_FULLROWSELECT);
// Add items to the list boxes
m_cmbSearch.AddString("Allow");
m_cmbSearch.AddString("Deny");
m_cmbSearch.SetCurSel(0);
m_cmbNode.AddString("Allow");
m_cmbNode.AddString("Deny");
m_cmbNode.SetCurSel(0);
// Set Reply to queries
if(Doc->m_MaxReplies)
{
m_chkReply.SetCheck(1);
m_ebReply.SetWindowText( DWrdtoStr(Doc->m_MaxReplies) );
}
else
{
m_ebReply.SetWindowText("Unlim.");
m_ebReply.EnableWindow(FALSE);
}
// Fill search filter list
std::vector<BlockedSearch>::iterator itBlock;
for(itBlock = Doc->SearchFilter.begin(); itBlock != Doc->SearchFilter.end(); itBlock++)
{
int row = m_lstSearch.GetItemCount();
m_lstSearch.InsertItem(row, (*itBlock).Name);
if( (*itBlock).Permis == 'A')
m_lstSearch.SetItemText(row, 1, "Allow");
else
m_lstSearch.SetItemText(row, 1, "Deny");
}
m_lstSearch.GetWindowRect(&rect);
if(m_lstSearch.GetScrollLimit(SB_VERT))
offSet = ::GetSystemMetrics(SM_CXVSCROLL) + 3;
else
offSet = 4;
m_lstSearch.SetColumnWidth(0, (rect.Width() - offSet) * 2/3);
m_lstSearch.SetColumnWidth(1, (rect.Width() - offSet) * 1/3);
// Fill filter list with items
std::vector<CString> FilterList;
CIPFilter::GetConfigStrings (FilterList);
std::vector<CString>::iterator itIP;
for(itIP = FilterList.begin(); itIP != FilterList.end(); itIP++)
{
int row = m_lstNode.GetItemCount();
CString Filter(*itIP);
Filter.Replace("-1", "*");
Filter.Replace(':', '.');
m_lstNode.InsertItem(row, Filter.Mid(2));
if(Filter.GetAt(0) == 'A')
m_lstNode.SetItemText(row, 1, "Allow");
else
m_lstNode.SetItemText(row, 1, "Deny");
}
m_lstNode.GetWindowRect(&rect);
if(m_lstNode.GetScrollLimit(SB_VERT))
offSet = ::GetSystemMetrics(SM_CXVSCROLL) + 3;
else
offSet = 4;
m_lstNode.SetColumnWidth(0, (rect.Width() - offSet) * 2/3);
m_lstNode.SetColumnWidth(1, (rect.Width() - offSet) * 1/3);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CPrefSearch::OnCheckReply()
{
if(m_chkReply.GetCheck())
{
m_ebReply.SetWindowText( DWrdtoStr(Doc->m_MaxReplies) );
m_ebReply.EnableWindow();
}
else
{
m_ebReply.SetWindowText("Unlim.");
m_ebReply.EnableWindow(FALSE);
}
SetModified();
}
void CPrefSearch::OnChangeEditReply()
{
SetModified();
}
void CPrefSearch::OnChangeEditSearch()
{
SetModified();
}
void CPrefSearch::OnEditchangeComboSearch()
{
SetModified();
}
void CPrefSearch::OnButtonSearchAdd()
{
CString newFilter;
m_ebSearch.GetWindowText(newFilter);
if(newFilter == "")
return;
// Get Allow / Deny permission
CString Permission;
m_cmbSearch.GetWindowText(Permission);
int row = m_lstSearch.GetItemCount();
m_lstSearch.InsertItem(row, newFilter);
m_lstSearch.SetItemText(row, 1, Permission);
// Resize the columns for scroll bars
CRect rect;
m_lstSearch.GetWindowRect(&rect);
int offSet;
if(m_lstSearch.GetScrollLimit(SB_VERT))
offSet = ::GetSystemMetrics(SM_CXVSCROLL) + 3;
else
offSet = 4;
m_lstSearch.SetColumnWidth(0, (rect.Width() - offSet) * 2/3);
m_lstSearch.SetColumnWidth(1, (rect.Width() - offSet) * 1/3);
SetModified();
}
void CPrefSearch::OnButtonSearchRemove()
{
if(m_lstSearch.GetSelectionMark() != -1)
m_lstSearch.DeleteItem( m_lstSearch.GetSelectionMark() );
// Resize the columns for scroll bars
CRect rect;
m_lstSearch.GetWindowRect(&rect);
int offSet;
if(m_lstSearch.GetScrollLimit(SB_VERT))
offSet = ::GetSystemMetrics(SM_CXVSCROLL) + 3;
else
offSet = 4;
m_lstSearch.SetColumnWidth(0, (rect.Width() - offSet) * 2/3);
m_lstSearch.SetColumnWidth(1, (rect.Width() - offSet) * 1/3);
SetModified();
}
void CPrefSearch::OnChangeEditNode()
{
SetModified();
}
void CPrefSearch::OnEditchangeComboNode()
{
SetModified();
}
void CPrefSearch::OnButtonNodeAdd()
{
CString newFilter;
m_ebNode.GetWindowText(newFilter);
// Check for 3 dots
int pos = 0;
for(int i = 0; i < 3; i++)
{
pos = newFilter.Find('.', pos) + 1;
if(pos == 0)
return;
}
// Get Allow / Deny permission
CString Permission;
m_cmbNode.GetWindowText(Permission);
int row = m_lstNode.GetItemCount();
m_lstNode.InsertItem(row, newFilter);
m_lstNode.SetItemText(row, 1, Permission);
// Resize the columns for scroll bars
CRect rect;
m_lstNode.GetWindowRect(&rect);
int offSet;
if(m_lstNode.GetScrollLimit(SB_VERT))
offSet = ::GetSystemMetrics(SM_CXVSCROLL) + 3;
else
offSet = 4;
m_lstNode.SetColumnWidth(0, (rect.Width() - offSet) * 2/3);
m_lstNode.SetColumnWidth(1, (rect.Width() - offSet) * 1/3);
}
void CPrefSearch::OnButtonNodeRemove()
{
if(m_lstNode.GetSelectionMark() != -1)
m_lstNode.DeleteItem( m_lstNode.GetSelectionMark() );
// Resize the columns for scroll bars
CRect rect;
m_lstNode.GetWindowRect(&rect);
int offSet;
if(m_lstNode.GetScrollLimit(SB_VERT))
offSet = ::GetSystemMetrics(SM_CXVSCROLL) + 3;
else
offSet = 4;
m_lstNode.SetColumnWidth(0, (rect.Width() - offSet) * 2/3);
m_lstNode.SetColumnWidth(1, (rect.Width() - offSet) * 1/3);
SetModified();
}
BOOL CPrefSearch::OnApply()
{
CString store;
// Set max reply settings
if(m_chkReply.GetCheck())
{
m_ebReply.GetWindowText(store);
Doc->m_MaxReplies = atoi(store);
}
else
Doc->m_MaxReplies = 0;
// Reload the search filter
Doc->SearchFilter.clear();
for(int row = 0; row < m_lstSearch.GetItemCount(); row++)
{
BlockedSearch Filter;
Filter.Name = m_lstSearch.GetItemText(row, 0);
Filter.Permis = m_lstSearch.GetItemText(row, 1).GetAt(0);
Doc->SearchFilter.push_back(Filter);
}
// Reload the node filter
CIPFilter::RemoveAll();
for(row = 0; row < m_lstNode.GetItemCount(); row++)
{
CString Filter( m_lstNode.GetItemText(row, 1).GetAt(0) );
Filter += ":" + m_lstNode.GetItemText(row, 0);
Filter.Replace("*", "-1");
Filter.Replace('.', ':');
CIPFilter::AddFilter(Filter);
}
if(m_lstSearch.GetItemCount() == 0)
{
BlockedSearch Search;
Search.Name = "*.*";
Search.Permis = 'A';
Doc->SearchFilter.push_back(Search);
}
if(m_lstNode.GetItemCount() == 0)
CIPFilter::AddFilter("A:-1:-1:-1:-1");
return CPropertyPage::OnApply();
}